#ifndef __SERVER_H__
#define __SERVER_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdatomic.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>

#define PORT 8080
#define BUFFER_SIZE 4096
#define THREAD_POOL_SIZE 10
#define TASK_QUEUE_CAPACITY 100

// 原子计数器（监控活跃连接）
extern atomic_int active_connections;

// 线程池任务结构
typedef struct {
    int client_fd;
} Task;

// 线程池结构
typedef struct {
    Task queue[TASK_QUEUE_CAPACITY];
    int capacity;
    int front;
    int rear;
    pthread_mutex_t lock;
    sem_t task_count;
} ThreadPool;

extern ThreadPool pool;
extern volatile sig_atomic_t shutdown_flag;
extern pthread_t worker_tids[THREAD_POOL_SIZE];

extern void thread_pool_init();
extern void thread_pool_add_task(int client_fd);
extern void thread_pool_clear();
extern void* worker_thread(void *arg);

#endif
